<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        function mergeSortedArr(a, b) {
            if (!a || !b) {
                return;
            };
            let aEle = a[0], bEle = b[0], i = 1, j = 1, res = [];
            while (aEle || bEle) {
                if ((aEle && !bEle) || aEle <= bEle) {
                    res.push(aEle);
                    aEle = a[i++];
                }
                else {
                    res.push(bEle);
                    bEle = b[j++];
                }
            }
            return res;
        }
        console.log(mergeSortedArr([2, 5, 6, 9], [1, 2, 3, 29]))  // [1,2,2,3,5,6,9,29]
    </script>
</body>

</html>